package routers

import (
	"uuMall/controllers"

	"github.com/beego/beego/v2/server/web"
	beego "github.com/beego/beego/v2/server/web"

	// "github.com/beego/beego/v2/server/web/context"
	"github.com/beego/beego/v2/server/web/filter/cors"
)

func init() {
	corsRules := &cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		AllowCredentials: true,
	}
	web.InsertFilter("*", web.BeforeStatic, cors.Allow(corsRules))
	// web.InsertFilter("*", web.BeforeRouter, func(ctx *context.Context) {
	// 	if ctx.Request.Method == "OPTIONS" {
	// 		ctx.ResponseWriter.WriteHeader(200)
	// 		ctx.ResponseWriter.Write([]byte("可以跨域"))
	// 		ctx.Output.Header("Access-Control-Allow-Origin", "*")
	// 	}
	// })
	beego.Router("/index", &controllers.MainController{})
	beego.Router("/user/beSeller", &controllers.BeSellerController{})
	beego.Router("/user/trolly", &controllers.TrollyController{})
	beego.Router("/user/preparedOrder", &controllers.PreparedOrderController{})
	beego.Router("/user", &controllers.UserController{})
	beego.Router("/gooddetail", &controllers.GooddetailController{})
	beego.Router("/admin/seller", &controllers.Admin_sellerController{})
	beego.Router("/gooddetail/commentAction", &controllers.CommentActionController{})
	beego.Router("/", &controllers.IndexController{})
	beego.Router("/api/login", &controllers.ApiLoginController{})
	beego.Router("/login", &controllers.LoginController{})
}
